package com.espirit.hr;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

import com.espirit.eap.annotation.Dict;
import com.espirit.eap.annotation.DomainModel;
import com.espirit.eap.manager.Department;
import com.espirit.eap.sa.Employee;
import com.espirit.eap.sa.User;
import com.espirit.finance.core.AcctTerm;
import com.espirit.finance.core.AcctTermCheckAware;

@Entity
@DomainModel
public class LeaveAppItem implements Serializable, EmployeeAware, VersionAware, AcctTermCheckAware{
	private static final long serialVersionUID = -5141608486414999149L;
	public static final String LEAVE_TYPE="leaveappitem_leavetype";
	
	public static final Integer LEAVE_TYPE_PERSONAL = 1;
	public static final Integer LEAVE_TYPE_SICK = 2;
	public static final Integer LEAVE_TYPE_MARRIAGE = 3;
	public static final Integer LEAVE_TYPE_MALERNLTY = 4;
	public static final Integer LEAVE_TYPE_ANNUAL = 5;
	public static final Integer LEAVE_TYPE_EXCHANGING = 6;
	public static final Integer LEAVE_TYPE_BEREVEMENT = 7;
	public static final Integer LEAVE_TYPE_OCCUPATION_INJURY = 8;
	public static final Integer LEAVE_TYPE_OTHERS = 9;
	
	private Integer id;
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	
	public BigDecimal getHours() {
		return hours;
	}
	public void setHours(BigDecimal hours) {
		this.hours = hours;
	}

	@ManyToOne
	public Employee getEmployee() {
		return employee;
	}
	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	@ManyToOne
	public Department getDepartment() {
		return department;
	}
	public void setDepartment(Department department) {
		this.department = department;
	}

	public Date getCreatedOn() {
		return createdOn;
	}
	public void setCreatedOn(Date createdOn) {
		this.createdOn = createdOn;
	}

	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Dict(type=LEAVE_TYPE)
	public Integer getLeaveType() {
		return leaveType;
	}
	public void setLeaveType(Integer leaveType) {
		this.leaveType = leaveType;
	}

	@ManyToOne
	public User getCreated() {
		return created;
	}
	public void setCreated(User created) {
		this.created = created;
	}
	
//	public Date getRealDate() {
//		return realDate;
//	}
//	public void setRealDate(Date realDate) {
//		this.realDate = realDate;
//	}


	public Date getBeginTime() {
		return beginTime;
	}
	public void setBeginTime(Date beginTime) {
		this.beginTime = beginTime;
	}

	public Date getEndTime() {
		return endTime;
	}
	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}
	
	@Transient
	public String getDeptIds() {
		return deptIds;
	}
	public void setDeptIds(String deptIds) {
		this.deptIds = deptIds;
	}
	
	private BigDecimal hours;
	private Employee employee;
	private Department department;
	private String remark;
	private Date createdOn;
	private Integer leaveType;
	private User created;
	private Date beginTime;
	private Date endTime;
	private String deptIds;

	@Override
	public boolean check(AcctTerm acctTerm) {
		if (acctTerm != null && acctTerm.getBeginDate() != null && this.beginTime != null){
			return acctTerm.getBeginDate().compareTo(this.beginTime) < 0;
		} else {
			return true;
		}
	}
	
}
